package cn.ming.wfchat.app.me.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.king.zxing.Intents;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.OnClick;
import cn.ming.wfchat.R;
import cn.ming.wfchat.app.AppService;
import cn.ming.wfchat.kit.WfcBaseActivity;
import cn.ming.wfchat.kit.qrcode.ScanQRCodeActivity;
import cn.wildfirechat.remote.ChatManager;

/**
 * @author luoming
 * created at 2020/8/11 3:04 PM
 * 使用新地址
 */
public class MyAssetsWithdrawalAddressActivity extends WfcBaseActivity {


    @BindView(R.id.et_tag)
    EditText etTag;
    @BindView(R.id.et_address)
    EditText etAddress;
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    @BindView(R.id.iv_san)
    ImageView ivSan;
    private static final int REQUEST_CODE_SCAN_QR_CODE = 100;

    @Override
    protected int contentLayout() {
        return R.layout.my_assets_withdrawa_addressl_activity;
    }


    @Override
    protected void afterViews() {
        super.afterViews();
        setTitle("使用新地址");
    }

    @OnClick(R.id.btn_submit)
    void setBtnSubmit() {
        String tag = etTag.getText().toString().trim();
        String address = etAddress.getText().toString().trim();
        if (TextUtils.isEmpty(tag)) {
            ChatManager.showToast("标签不能为空");
            return;
        }
        if (TextUtils.isEmpty(address)) {
            ChatManager.showToast("地址不能为空");
            return;
        }
        AppService.Instance().addWithdrawAddress(address, tag, new AppService.SendCodeCallback() {
            @Override
            public void onUiSuccess() {
                ChatManager.showToast("操作成功");
                finish();
            }

            @Override
            public void onUiFailure(String msg) {
                ChatManager.showToast(msg);

            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_CODE_SCAN_QR_CODE) {
                String result = data.getStringExtra(Intents.Scan.RESULT);
                etAddress.setText(result);
            }
        }
    }

    @OnClick(R.id.iv_san)
    void setIvSan() {
        startActivityForResult(new Intent(this, ScanQRCodeActivity.class), REQUEST_CODE_SCAN_QR_CODE);
    }
}
